package com.lqm.util;

import com.lqm.entity.home.Project;
import com.lqm.entity.home.ProjectVo;
import com.lqm.entity.home.Slide;
import com.lqm.entity.home.SlideVo;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.NumberFormat;

/**
 * @program: CrowdFunding
 * @description
 * @author: lqm
 * @create: 2018-12-13 21:50
 */

public class ClassVoUtil {

    public static ProjectVo ProjectCastProjectVo(Project project,double supportSumByProject) {
        ProjectVo projectVo = new ProjectVo();
        projectVo.setDay(project.getDay());
        projectVo.setBanner(project.getBanner());
        projectVo.setDescription(project.getDescription());
        projectVo.setDetail(project.getDetail());
        projectVo.setEndTime(project.getEndTime());
        projectVo.setHomeUser(project.getHomeUser());
        projectVo.setMoney(project.getMoney());
        projectVo.setName(project.getName());
        projectVo.setProjectId(project.getProjectId());
        projectVo.setProjectStatus(project.getProjectStatus());
        projectVo.setProjectType(project.getProjectType());
        projectVo.setSingleCount(project.getSingleCount());
        projectVo.setSingleMoney(project.getSingleMoney());
        projectVo.setStartTime(project.getStartTime());
        projectVo.setStatus(project.getStatus());
        projectVo.setCreateTime(project.getCreateTime());
        projectVo.setCommodityDescription(project.getCommodityDescription());


        projectVo.setCurrentAllMoney(supportSumByProject+"");

        //项目当前获得的金额
        BigDecimal currentMonery = new BigDecimal(Double.toString(supportSumByProject));

        //项目所需要的金额
        BigDecimal allMoney = project.getMoney();

        //百分比
        BigDecimal divide = currentMonery.divide(allMoney, RoundingMode.CEILING);
//            System.out.println("divide"+divide);
        NumberFormat nf = NumberFormat.getPercentInstance();
        nf.setMaximumFractionDigits(0);
        //真实的完成百分比
        String trueFormat = nf.format(divide);
//            System.out.println("divide.compareTo(new BigDecimal(1.0))"+divide.compareTo(new BigDecimal(1.0)));
        if(divide.compareTo(new BigDecimal(1.0))>=0){ //超过100%
            projectVo.setAllPercent("100%");
        }else {
            projectVo.setAllPercent(trueFormat);
        }
        projectVo.setTruePercent(trueFormat);


        System.out.println(trueFormat);




        return projectVo;
//        return null;
    }






    public static SlideVo SlideVoCastSlideVoVo(Slide slide) {
        SlideVo slideVo = new SlideVo();
//        slideVo.setProject(slide.getProject());
        slideVo.setBannerImg(slide.getBannerImg());
        slideVo.setSlideId(slide.getSlideId());
        slideVo.setStatus(slide.getStatus());
        return slideVo;
    }
}